package com.jackchen.dao;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;

public interface IBaseDAO {

	//public void init();
	
	public <E> E findById(Class<E> entityClass, Serializable id);
	
	/*
	 * @param aClassName,是要实现分页的对应对象类型名;aPageSize,每页的页数;aStartRow,起始查询记录
	 */
	public Map findByPage(String aClassName,int aPageSize,int aStartRow);
	
	/*
	 * @param aClassName,是要实现查询单表所有记录对应的类名
	 */
	public List findAll(String aClassName) throws DataAccessException;
	
	/*
	 *  Execute a named query.
	 */
	public List findByNamedQuery(String queryName, Object value) throws DataAccessException;
	
	/*
	 * Execute a named query binding a number of values to "?" parameters in the query string.
	 */
	public List findByNamedQuery(String queryName, Object... values);
	
	/*
	 * Execute an HQL query, binding one value to a ":" named parameter in the query string.
	 */
	public List findByNamedParam(String queryString, String paramName, Object value)
			throws DataAccessException;
	/*
	 * Execute an HQL query, binding a number of values to ":" named parameters in the query string.		
	 */
			
	public List findByNamedParam(final String queryString, final String[] paramNames, final Object[] values)
			throws DataAccessException;
	
	/*
	 *  Persist the given transient instance.
	 */
	public Serializable save(final Object entity);
	
	
	
	/*
	 *  Update the given persistent instance, associating it with the current Hibernate Session.
	 */
	public void update(Object entity) throws DataAccessException;
	
	
	
	/*
	 *  Persist the given transient instance.
	 */
	public void saveOrUpdate(final Object entity) throws DataAccessException;
	
	
	
	/*
	 *  Save or update the given persistent instance, 
	 *  according to its id (matching the configured "unsaved-value"?).
	 */
	public void saveOrUpdateAll(final List entities) throws DataAccessException;
	
	
	
	/*
	 *  Delete the given persistent instance.
	 */
	public void delete(Object entity) throws DataAccessException;
	
	/*
	 * Delete By Id
	 */
	
	public <T> void deleteById(Class<T> entityClass, Serializable id) throws DataAccessException;
	
	
	
	/*
	 *  Delete all given persistent instances.
	 */
	public void deleteAll(final List entities) throws DataAccessException;
	
	
	
	/*
	 *  Execute a query based on the given example entity object.
	 */
	public List findByExample(Object exampleEntity) throws DataAccessException;
	
	
	
	/*
	 *  Copy the state of the given object onto the persistent object with the same identifier.
	 */
	public <T> T merge(final String entityName, final T entity) throws DataAccessException;
	
	/**
	 * 根据原生SQL操作数据库
	 * @param sql
	 * @param objects
	 * @return
	 */
	public List<Object> findObjBySql(String sql, Object...objects);
	
	/**
	 * 根据HSQL操作数据库
	 * @param sql
	 * @param objects
	 * @return
	 */
	public List<Object> findObjByHSql(String sql, Object...objects);

	/**
	 * 执行动态的HSQL语句，并带有分页功能
	 * 
	 * @param sql
	 * @param aPageSize
	 * @param aStartRow
	 * @param objects
	 * @return
	 */
	public Map findObjBySqlPage(String sql, final int aPageSize, final int aStartRow, Object...objects);
	
	/**
	 * 根据Column查询对象列表
	 * @param tableName
	 * @param obj
	 * @return
	 */
	public List<Object> findObjByColumn(String tableName, Object... obj);
	
	public <T> void sessionLoad(Class<T> entityClass,Serializable id);
}
